<?php
namespace app\admin\controller;

use think\Db;
use think\Controller;
use think\Request;

class Index extends Base{
    public function _initialize(){
        parent::_initialize(); //
    }

    public function index(){
        return view();
    }
    public function welcome(){
        $version = Db::query('SELECT VERSION() AS ver');
        $config  = [
            'url'             => $_SERVER['HTTP_HOST'],
            'tpver'           => THINK_VERSION,
            'document_root'   => $_SERVER['DOCUMENT_ROOT'],
            'server_os'       => PHP_OS,
            'server_port'     => $_SERVER['SERVER_PORT'],
            'server_ip'       => $_SERVER['SERVER_ADDR'],
            'server_soft'     => $_SERVER['SERVER_SOFTWARE'],
            'php_version'     => PHP_VERSION,
            'mysql_version'   => $version[0]['ver'],
            'disk_free_space' => number_format(disk_free_space('/')/1048576,2),
            'max_upload_size' => ini_get('upload_max_filesize')
        ];
        //分配变量
        $this -> assign('config',$config);
        return view();
    }
    /**/
    public function welcome1(){
        return view();
    }

    /*  脚本
     *
     * ***/
    public function shelldata(){
        $brandModel = new \app\admin\model\Brand();
        $data = $brandModel -> getBrandDataForListByWhere(['status'=>1],'id desc',false ,1);
        $this -> modifyField($data);
//        dump($data);

    }

    /**/
    public function modifyField($data){
        foreach ($data as $key => $value) {
            if($value['desc']){
                $save['ceo'] = $value['desc']['ceo'];
            }
            if($value['company']){
                $save['logo'] = $value['company']['logo'];
                $save['cname'] = $value['company']['name'];
                $save['province'] = empty($value['company']['province']) ? 1 : $value['company']['province'];
                $save['city'] = empty($value['company']['city']) ? 1 : $value['company']['city'];
            }
            $save['lastlog'] = time();
            $res = db('brand') -> where('id',$value['id']) -> update($save);
            dump($res);

        }
    }

}
